package com.uni.utils;

import java.util.*;

public class CollectionUtil {
	/*
	 * I can't mapping map :(
	 * So, I map list and than translate it into map.
	 * In future, I'll mapping map.
	 * 
	 * Using public field with name fieldName as key for Map
	 * */
	public static <T> Map<Object, T> buildMap(Collection<T> list, String fieldName)
		throws IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException{
		Map<Object, T> m = new HashMap<Object, T>();
		for(T el : list ){
			Object key = el.getClass().getDeclaredField(fieldName).get(el);
			m.put(key, el);
		}
		return m;
	}
}
